// Package toast Package syst
// @Author: zhangdi
// @File: toast
// @Version: 1.0.0
// @Date: 2023/5/24 19:00
package notify

import (
	"errors"
	"github.com/gen2brain/beeep"
	"ideatools/application/constant"
	"runtime"
)

type Toast struct {
	lastError error
}

func NewToast() *Toast {
	return &Toast{}
}

func StartToast(title, content string) *Toast {
	s := &Toast{}
	err := s.ShowToast(title, content)
	s.lastError = err
	return s
}

// ErrorCheck 检测是否存在error 如果存在则返回错误内容同时将lastError置为nil
func (t *Toast) ErrorCheck() string {
	if t.lastError != nil {
		t.lastError = nil
		return t.lastError.Error()
	}

	return ""
}

func (t *Toast) ShowToast(title, content string) error {
	switch runtime.GOOS {
	case constant.SystemTypeWindows:
		return showToastWin(title, content)
		break
	case constant.SystemTypeLinux:
		break
	case constant.SystemTypeMac:
		showToastMac(title, content)
		break
	}

	return errors.New("当前平台暂时不支持通知：" + runtime.GOOS)
}

// 显示系统--windows
func showToastWin(title, content string) error {
	return beeep.Notify(title, content, "")
}

func showToastMac(title, content string) error {
	return beeep.Alert("Title", "Message body", "assets/warning.png")
}
